package com.nuc.iblog.controler;

import com.nuc.iblog.entity.Announcement;
import com.nuc.iblog.service.imp.MSAnnouncementService;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


@Controller
@RequestMapping("/ms")
public class MSAnnouncementController {
    @Autowired
    MSAnnouncementService msAnnouncementService;

    @ResponseBody
    @RequestMapping("/createAnnouncement")
    public Map<String,Object> createAnnouncement(@RequestParam("content")String content){
        Map<String, Object> returnMap=new HashMap<String, Object>();
        msAnnouncementService.CreateAnnouncement(content);
        returnMap.put("code",1);
        return returnMap;
    }

    @ResponseBody
    @RequestMapping("/getLatestAnnouncement")
    public Announcement getLatestAnnouncement(){
        return msAnnouncementService.getLatesetAnnouncement();
    }

    @RequestMapping("/getAllAnnouncement")
    public String getAllAnnouncement(HttpServletRequest request){
        request.setAttribute("announcements",msAnnouncementService.getAllAnnouncements());
        return "/announcementList";
    }

}

